home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- /* Define a table of function names and numbers */
-
-
- #define CNTRL 0
- #define DIGIT 1
- #define GRAPH 2
- #define LOWER 3
- #define PRINT 4
- #define PUNCT 5
- #define SPACE 6
- #define UPPER 7
- #define XDIGIT 8
-
- typedef struct FUNC_TABLE
- {
- char name[16];
- int funcnum;
- }FUNC_TABLE;
-
- /* Now declare the table and initialize it */
- static FUNC_TABLE isfuncs[9] =
- {
- "iscntrl", CNTRL, "isdigit", DIGIT,
- "isgraph", GRAPH, "islower", LOWER,
- "isprint", PRINT, "ispunct", PUNCT,
- "isspace", SPACE, "isupper", UPPER,
- "isxdigit" , XDIGIT
- };
- static int numfunc = sizeof(isfuncs)/sizeof(FUNC_TABLE);
- main(int argc, char **argv)
- {
- int ch, count, i, test_result,
- mark = 0xdb; /* to mark characters */
- if (argc < 2)
- {
- printf("Usage: %s <function_name>\n", argv[0]);
- exit(0);
- }
-
- /* Search table for function name and pointer */
-
- for(i=0; i<numfunc; i++)
- {
- if (strcmp(argv[1], isfuncs[i].name) == 0)
- break;
- }
- if (i >= numfunc)
- {
- printf("Unknown function: %s\n", argv[1]);
- exit(0);
- }
-
- /* Now go over entire ascii table and mark the
- * characters that satisfy requested test.
- */
-
- printf(
- "Those marked with a %c satisfy %s\n",
- mark, argv[1]);
- for(count = 0, ch = 0; ch <= 0x7f; ch++)
- {
- printf("%#02x ", ch);
-
- /* Print character -- if printable */
-
- if(isprint(ch))
- {
- printf(" %c", ch);
- }
- else
- {
- printf(" ");
- }
-
- /* Perform the test and put a mark if test succeeds */
-
- switch(isfuncs[i].funcnum)
- {
- case CNTRL: test_result = iscntrl(ch);
- break;
- case DIGIT: test_result = isdigit(ch);
- break;
- case GRAPH: test_result = isgraph(ch);
- break;
- case LOWER: test_result = islower(ch);
- break;
- case PRINT: test_result = isprint(ch);
- break;
- case PUNCT: test_result = ispunct(ch);
- break;
- case SPACE: test_result = isspace(ch);
- break;
- case UPPER: test_result = isupper(ch);
- break;
- case XDIGIT:test_result = isxdigit(ch);
- break;
- }
- if(test_result != 0)
- {
- printf("%c ", mark);
- }
- else
- {
- printf(" ",ch);
- }
- count++;
- if(count == 8)
- {
- printf(" \n");
- count = 0;
- }
- }
- }